package com.handong.handserialprogram.module.createmission;

import android.support.annotation.NonNull;
import android.view.View;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.handong.handserialprogram.R;
import com.handong.handserialprogram.module.base.BackStackFragment;
import com.handong.handserialprogram.module.createmission.recordtask.RecordTaskFragment;
import com.handong.handserialprogram.module.createmission.searchring.SearchRingFragment;

/**
 * CreateMissionFragment：选择创建任务方式。
 */
public class CreateMissionFragment extends BackStackFragment {

    public CreateMissionFragment() {
    }

    public static CreateMissionFragment newInstance() {
        CreateMissionFragment fragment = new CreateMissionFragment();
        return fragment;
    }


    @Override
    protected void initViewByID(View contentView) {
//        contentView.findViewById(R.id.haveMissionCriminal).setOnClickListener(this);
//        contentView.findViewById(R.id.noMissionCriminal).setOnClickListener(this);
//
//        initHeaderLayout(R.string.create_mission_title);
        //直接进入用户模式
        addFrag(RecordTaskFragment.newInstance(), R.id.createMissionContainer);
    }

    @Override
    protected int getContentViewID() {
        return R.layout.fragment_create_mission;
    }

    @Override
    public void onClick(View v) {
        if (dispatchDoubleClick()) {
            return;
        }
        switch (v.getId()) {
            case R.id.noMissionCriminal://快捷创建
                //addFrag(SearchRingFragment.newInstance(), R.id.createMissionContainer);
                break;
            case R.id.haveMissionCriminal://用户模式
                addFrag(RecordTaskFragment.newInstance(), R.id.createMissionContainer);
                break;
            default:
                super.onClick(v);
        }
    }

    private void showSureDialog() {
        MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
                .title(R.string.dialog_title_careful)
                .content("被创建的任务将不会包含押解人员、规划路线以及使用车辆。 \n\n是否确认要创建？")
                .positiveText(R.string.dialog_positive_text)
                .positiveColorRes(R.color.back_ground_green)
                .negativeText(R.string.dialog_negative_text)
                .negativeColorRes(R.color.dialog_bg)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        pushMissionToServer();
                    }
                })
                .build();
        dialog.show();
    }

    private void pushMissionToServer() {
        //addFrag(SearchRingFragment.newInstance(), R.id.createMissionContainer);
    }
}
